package com.ytjj.qmyx.admin.controller.imController;

import com.ytjj.common.api.CommonResult;
import com.ytjj.common.exception.ApiException;
import com.ytjj.qmyx.admin.annotation.OperLog;
import com.ytjj.qmyx.admin.constants.SysLogConstants;
import com.ytjj.qmyx.admin.eunm.im.ImRepositoryEnums;
import com.ytjj.qmyx.admin.model.ImKeyClassify;
import com.ytjj.qmyx.admin.service.imService.ImKeyClassifyService;
import com.ytjj.qmyx.admin.utils.EmptyUtil;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * 
 * 关键分类
 */
@RestController
@AllArgsConstructor
@RequestMapping("/keyClassify")
public class ImKeyClassifyController {

    private ImKeyClassifyService imKeyClassifyService;

    @PostMapping("/classifyList")
    @OperLog(operModule = "关键分类", operDesc = "关键分类列表", operType = SysLogConstants.OPERATION_SELECT)
    public CommonResult classifyList() {
        return CommonResult.success(imKeyClassifyService.classifyList());
    }

    @PostMapping(value = "/insertClassify")
    @OperLog(operModule = "关键分类", operDesc = "新增关键分类", operType = SysLogConstants.OPERATION_ADD)
    public CommonResult insertClassify(@RequestBody ImKeyClassify imKeyClassify){
        if(EmptyUtil.isEmpty(imKeyClassify.getName())){
            return CommonResult.failed(ImRepositoryEnums.CLASSIFY_NAME_NULL.getMessage());
        }
        return CommonResult.success(imKeyClassifyService.insertClassify(imKeyClassify));
    }

    @GetMapping(value = "/deleteClassify")
    @OperLog(operModule = "关键分类", operDesc = "移除关键分类", operType = SysLogConstants.OPERATION_UPDATE)
    public CommonResult deleteClassify(Integer id){
        if(EmptyUtil.isEmpty(id)){
            throw new ApiException(ImRepositoryEnums.KEY_CLASSIFY_IS_NULL.getMessage());
        }
        return CommonResult.success(imKeyClassifyService.deleteClassify(id));
    }

    @PostMapping(value = "/updateClassify")
    @OperLog(operModule = "关键分类", operDesc = "修改关键分类", operType = SysLogConstants.OPERATION_UPDATE)
    public CommonResult updateClassify(@RequestBody ImKeyClassify imKeyClassify){
        if(EmptyUtil.isEmpty(imKeyClassify.getName())){
            return CommonResult.failed(ImRepositoryEnums.CLASSIFY_NAME_NULL.getMessage());
        }
        return CommonResult.success(imKeyClassifyService.updateClassify(imKeyClassify));
    }

    @GetMapping(value = "/selectClassify")
    @OperLog(operModule = "关键分类", operDesc = "按关键ID查询关键分类信息", operType = SysLogConstants.OPERATION_SELECT)
    public CommonResult selectClassify(Integer id){
        if(EmptyUtil.isEmpty(id)){
            throw new ApiException(ImRepositoryEnums.KEY_CLASSIFY_IS_NULL.getMessage());
        }
        return CommonResult.success(imKeyClassifyService.selectClassify(id));
    }

}
